using Microsoft.Synchronization;
using Microsoft.Synchronization.Data;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;

namespace Cesave.DistributedServices.Permisos.SynchronizationModule
{


	public partial class PermisosCacheServerSyncProvider
	{
		partial void OnInitialized()
		{
			ApplyChangeFailed += PermisosCacheServerSyncProvider_ApplyChangeFailed;
		}

		private void PermisosCacheServerSyncProvider_ApplyChangeFailed(object sender, ApplyChangeFailedEventArgs e)
		{
			ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
			switch (e.Conflict.ConflictType)
			{
				case ConflictType.ClientDeleteServerUpdate:
					e.Action = ApplyAction.RetryWithForceWrite;
					break;
				case ConflictType.ClientInsertServerInsert:
					e.Action = ApplyAction.RetryWithForceWrite;
					break;
				case ConflictType.ClientUpdateServerDelete:
					e.Action = ApplyAction.RetryWithForceWrite;
					break;
				case ConflictType.ClientUpdateServerUpdate:
					e.Action = ApplyAction.RetryWithForceWrite;
					break;
				case ConflictType.ErrorsOccurred:
					break;
				case ConflictType.Unknown:
					break;
				default:
					break;
			}
		}
	}
}
